//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.product;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.live.base.domain.LiveProductSource;
import com.ruoyi.live.product.service.LiveProductSourceService;
import com.ruoyi.live.tool.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

@Controller("oldLiveProductSourceController")
@RequestMapping({"/product"})
public class LiveProductSourceController extends BaseController {
    @Autowired
    LiveProductSourceService service;

    public LiveProductSourceController() {
    }

    @RequestMapping({"/LiveProductSourceController/index"})
    public ModelAndView index(Long id) {
        return new ModelAndView("product/live_product_source_main_pic");
    }

    @RequestMapping({"/LiveProductSourceController/contentIndex"})
    public ModelAndView contentIndex(Long id) {
        return new ModelAndView("product/live_product_source_content_pic");
    }

    @ResponseBody
    @RequestMapping({"/LiveProductSourceController/query"})
    public TableDataInfo query(LiveProductSource entity) {
        this.startPage();
        List<LiveProductSource> list = this.service.query(entity);
        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/LiveProductSourceController/add"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message add(LiveProductSource entity) {
        try {
            this.service.addLiveProductSource(entity);
            return new Message(true, "新增成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveProductSourceController/update"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message update(LiveProductSource entity) {
        try {
            this.service.updateLiveProductSource(entity);
            return new Message(true, "修改成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveProductSourceController/delete"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message delete(String id) {
        try {
            this.service.deleteLiveProductSource(id.split(","));
            return new Message(true, "删除成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @RequestMapping({"/LiveProductSourceController/view"})
    public ModelAndView view(Long id, String page) {
        ModelAndView mv = new ModelAndView("product/" + page);
        if (id != null) {
            try {
                mv.addObject("entity", this.service.getLiveProductSource(id));
            } catch (Exception var5) {
                return (new ModelAndView("error")).addObject("tip", var5.getMessage());
            }
        }

        return mv;
    }

    @ResponseBody
    @RequestMapping({"/upload"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message upload(Long id, Integer type, Integer section, HttpServletRequest request) {
        return this.service.upload(id, type, section, request);
    }

    @ResponseBody
    @RequestMapping({"/getSources"})
    public List<LiveProductSource> getSources(Integer type, Long productId) {
        return this.service.getSources(type, productId);
    }

    @ResponseBody
    @RequestMapping({"/setSection"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message setSection(Long id, Integer section) {
        try {
            this.service.setSection(id, section);
            return new Message(true, "");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/getContentSources"})
    public List<List<LiveProductSource>> getContentSources(Long productId) {
        return this.service.getContentSources(productId);
    }

    @ResponseBody
    @RequestMapping({"/picSetting"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message picSetting(LiveProductSource entity) {
        try {
            this.service.picSetting(entity);
            return new Message(true, "设置成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, "设置失败");
        }
    }

    @RequestMapping({"/large"})
    public ModelAndView large(Long id) {
        return (new ModelAndView("product/live_product_source_pic_large")).addObject("obj", this.service.getLiveProductSource(id));
    }
}
